package com.yonyou.pmclouds.inspectitem.process;

import org.apache.commons.lang3.ArrayUtils;

import com.yonyou.pmclouds.basecom.bp.processor.MultiProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.inspectitem.entity.InspectItemBillStatusConst;
import com.yonyou.pmclouds.inspectitem.entity.InspectItemVO;
/**
 * 检查项新增前规则
 * @author fangpengc
 *
 */
public class InspectItemAddBeforeProcess implements MultiProcessor<InspectItemVO>{

    @Override
    public void process(InspectItemVO[] vos, InspectItemVO[] origs) throws BusinessException {
        if (ArrayUtils.isEmpty(vos)) {
            return;
        }
        for (InspectItemVO inspectItemVO : vos) {
            byte status = inspectItemVO.getBillstatus();
            // 判断是否为三种状态中的一种
            if (status != InspectItemBillStatusConst.BILLSTATUS_PASS &&
                    status != InspectItemBillStatusConst.BILLSTATUS_NO_PASS &&
                    status != InspectItemBillStatusConst.BILLSTATUS_NOT_FIT) {
                throw new BusinessException("请选择检查项状态为必选项!");
            }
            if (inspectItemVO.getMemo() != null && inspectItemVO.getMemo().length() > 300) {
                throw new BusinessException("检查项备注最多只能有300个字！");
            }
            if (inspectItemVO.getImprovement_area() != null && inspectItemVO.getImprovement_area().length() > 300) {
                throw new BusinessException("整改区域最多只能有300个字！");
            }
        }
    }

}

